﻿Imports System.Runtime.Serialization
'Imports System.ComponentModel

<Serializable()> _
Public Class clsBaseClass
	Implements IDisposable, ISerializable ', INotifyPropertyChanged

	Private strID As String
	Private strName As String

	Private disposedValue As Boolean
	Private booEnabled As Boolean

	Private Shared rnd As New Random()

	Public Event Disposed(ByVal sender As Object, ByVal e As System.EventArgs)

	Public Overridable Property Name() As String
		Get
			Return strName
		End Get
		Set(ByVal value As String)
			strName = value
		End Set
	End Property

	Public Overridable Property Enabled() As Boolean
		Get
			Return booEnabled
		End Get
		Set(ByVal value As Boolean)
			booEnabled = value
		End Set
	End Property

	Public Overridable Property ID() As String
		Get
			Return strID
		End Get
		Set(ByVal value As String)
			strID = value
		End Set
	End Property

	Public Sub New()
		Init()
	End Sub

	Public Sub New(ByVal strName As String)
		Init()
		Name = strName
	End Sub

	Public Overrides Function ToString() As String
		Return Name
	End Function

	Private Sub Init()
		Name = [GetType]().Name
		ID = rnd.Next(1, 999999)
	End Sub

	Protected Overrides Sub Finalize()
		Dispose()
		MyBase.Finalize()
	End Sub

	' IDisposable
	Protected Overridable Sub Dispose(ByVal disposing As Boolean)
		If Not Me.disposedValue Then
			If disposing Then
				Name = Nothing
				ID = Nothing
			End If
			RaiseEvent Disposed(Me, EventArgs.Empty)
		End If
		Me.disposedValue = True
	End Sub

#Region " IDisposable Support "
	' This code added by Visual Basic to correctly implement the disposable pattern.
	Public Overridable Sub Dispose() Implements IDisposable.Dispose
		' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
		Dispose(True)
		GC.SuppressFinalize(Me)
	End Sub
#End Region

	Public Overridable Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext) Implements System.Runtime.Serialization.ISerializable.GetObjectData
		info.AddValue("Name", Name)
		info.AddValue("ID", ID)
		info.AddValue("Enabled", Enabled)
	End Sub

	'Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

	'Protected Overridable Sub OnPropertyChanged(ByVal strPropName As String)
	'	RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(strPropName))
	'End Sub
End Class
